#include "Timer.h"
#include "Potentiometer.h"

/* CONSTRUCTOR */
Potentiometer::Potentiometer(PotentiometerListener* potentiometerListener, int potentiometerPort)
{
  Timer* t = Timer::getTimer();
  m_potentiometerPort = potentiometerPort;
  m_potentiometerListener = potentiometerListener;
  t->every( 100, this);
}

/* METHODES */

/**
* \brief Verify if switch position has changed and update its state
* \param eventId
* \return none
*/
void Potentiometer::timerCallbackFunction(int eventId)
{
  int newValue = analogRead(m_potentiometerPort);
  int delta = newValue - m_value;
  if (abs(delta) >= 4)
  {
    m_value = newValue;
    m_potentiometerListener->potentiometerPositionChanged(m_value);
  }
  else
  {
    /* value hasn't change enough, nothing to do */
  }
}


